package cn.good.biz.service;

import cn.good.mapper.AttentionMapper;
import cn.good.mapper.CommentMapper;
import cn.good.mapper.DoctorMapper;
import cn.good.mapper.ServicePriceMapper;
import cn.good.pojo.Attention;
import cn.good.pojo.Comment;
import cn.good.pojo.Doctor;
import cn.good.pojo.ServicePrice;
import cn.good.service.DoctorService;
import cn.good.vo.DoctorInfoVO;
import cn.good.vo.ServicePriceVO;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service(interfaceClass = DoctorService.class)
@Component
public class DoctorServiceImpl implements DoctorService {

    @Resource
    private DoctorMapper doctorMapper;
    @Resource
    private AttentionMapper attentionMapper;
    @Resource
    private CommentMapper commentMapper;
    @Resource
    private ServicePriceMapper servicePriceMapper;

    /**
     * 查询医生信息
     * @param id
     * @return
     */
    @Override
    public DoctorInfoVO selectInfoById(Long id) {
        return doctorMapper.selectByPrimaryKey(id);
    }

    /**
     * 关注医生
     * @param userId
     * @param doctorId
     * @return
     */
    @Override
    public boolean insertAtention(Long userId, Long doctorId) {

        Attention attention = new Attention();
        attention.setUserId(Integer.parseInt(userId.toString()));
        attention.setDoctorId(Integer.parseInt(doctorId.toString()));
        attention.setCreatedBy(userId);
        attention.setCreationDate(new Date());
        attentionMapper.insert(attention);

        return attentionMapper.insert(attention)>0;
    }

    /**
     * 取关
     * @param userId
     * @param doctorId
     * @return
     */
    @Override
    public boolean updateAtention(Long userId, Long doctorId) {

        return attentionMapper.updateByUserId(userId,doctorId)>0;

    }

    /**
     * 查询用户关注医生
     * @param userId
     * @return
     */
    @Override
    public List<Doctor> searchDoctorByUserId(Long userId) {
        return doctorMapper.selectListByUserId(userId);
    }

    /**
     * 查询评论列表
     * @param doctorId
     * @return
     */
    @Override
    public List<Comment> searchCommentByDoctorId(Long doctorId) {
        return commentMapper.selectListByDoctorId(doctorId);
    }

    /**
     * 查询医生金额服务列表
     * @param doctorId
     * @return
     */
    @Override
    public List<ServicePriceVO> searchServicePriceByDoctorId(Long doctorId) {

        return servicePriceMapper.selectListByDoctorID(doctorId);
    }
}
